//
//  GXShopServiceCell.m
//  YIChuSeller
//
//  Created by 田小椿 on 2019/1/8.
//  Copyright © 2019年 xiangshengjun. All rights reserved.
//

#import "GXShopServiceCell.h"
#import "UIButton+IconPosition.h"
@interface GXShopServiceCell ()
@property (nonatomic,strong)UIView *totalView;
@property (nonatomic,strong)UIView * oneLineView;
@property (nonatomic,strong)UIView * twoLineView;
@property (nonatomic,strong)UIImageView * timeImageView;
@property (nonatomic,strong)UIImageView * locationImageView;
@property (nonatomic,strong)UILabel * timeLabel;
@property (nonatomic,strong)UILabel * locationLabel;
@property (nonatomic,strong) NSDictionary * titleKeyDic;
@property (nonatomic,strong) NSDictionary * imageKeyDic;
@end
@implementation GXShopServiceCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
         [self setupShopServiceView];
    }
    return self;
}
- (void)setServiceDict:(NSDictionary *)serviceDict
{
    _serviceDict = serviceDict;
    NSArray * serviceArray = [serviceDict[@"serviceSige"]  componentsSeparatedByString:@"-"];
    if (!serviceArray.count) {
        return;
    }
    NSInteger viewYFrame = serviceArray.count / 5 ;
    NSInteger index = serviceArray.count % 5;
    NSInteger viewY = index ?(viewYFrame + 1) * 45 : viewYFrame*45;
    self.oneLineView.frame = CGRectMake(5, viewY +40, kUIScreenWidth-20, 1);
    self.timeImageView.frame = CGRectMake(10,viewY+51, 20 , 20);
    self.timeLabel.frame =CGRectMake(35, viewY+51, kUIScreenWidth-50, 20);
    self.twoLineView.frame =CGRectMake(5, viewY +81, kUIScreenWidth-20, 1);
    self.locationImageView.frame =CGRectMake(10,viewY+92, 20 , 20);
    self.locationLabel.frame =CGRectMake(35, viewY+92, kUIScreenWidth-50, 20);
    self.totalView.frame =CGRectMake(10, 0, kUIScreenWidth-20, viewY+122);
    self.frame = CGRectMake(0, 0, kUIScreenWidth, viewY+130);
//    self.headerViewHeight = viewY+357;
    NSString *dayStr = [NSString getDayString:self.serviceDict[@"businesSige"]];
    self.timeLabel.text = [NSString stringWithFormat:@"%@ %@",dayStr,self.serviceDict[@"businesstime"]];
    self.locationLabel.text = self.serviceDict[@"address"];
}

- (void)handleServiceArray:(NSArray *)serviceArray
{
    CGFloat Start_X = 10;
    CGFloat Start_Y = 40;
    CGFloat Width_Space = 0;
    CGFloat Height_Space  = 0;
    CGFloat btn_heigth = 45;
    CGFloat btn_width = (kUIScreenWidth-40)/5;
    for (int i= 0; i<serviceArray.count;i++) {
        NSInteger index = i % 5;
        NSInteger page = i / 5;
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString * imageStr = [self.imageKeyDic objectForKey:serviceArray[i]];
        [button setImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [button setBackgroundColor:[UIColor clearColor]];
        NSString *titleStr =[self.titleKeyDic objectForKey:serviceArray[i]];
        [button setTitle:titleStr forState:UIControlStateNormal];
        button.frame = CGRectMake(index * (btn_width + Width_Space) + Start_X, page  * (btn_heigth + Height_Space)+Start_Y, btn_width, btn_heigth);
        [button setIconInTopWithSpacing:3];
        [self.totalView addSubview:button];
    }
}
- (NSDictionary *)titleKeyDic
{
    if (_titleKeyDic ==nil) {
        _titleKeyDic = [NSDictionary dictionary];
        _titleKeyDic= @{
                        @"A":@"露天座",
                        @"B":@"包间",
                        @"C":@"WIFI",
                        @"D":@"宝宝椅",
                        @"E":@"停车",
                        @"F":@"防油服",
                        @"G":@"游乐区",
                        @"H":@"刷卡",
                        @"I":@"无烟区",
                        @"J":@"可吸烟",
                        @"K":@"沙发位",
                        };
    }
    return _titleKeyDic;
}
- (NSDictionary *)imageKeyDic
{
    if (_imageKeyDic == nil) {
        _imageKeyDic = [NSDictionary dictionary];
        _imageKeyDic = @{
                         @"A":@"home_service11normal",
                         @"B":@"home_service12normal",
                         @"C":@"home_service13normal",
                         @"D":@"home_service14normal",
                         @"E":@"home_service15normal",
                         @"F":@"home_service21normal",
                         @"G":@"home_service22normal",
                         @"H":@"home_service23normal",
                         @"I":@"home_service24normal",
                         @"J":@"home_service25normal",
                         @"K":@"home_service31normal",
                         };
    }
    return _imageKeyDic;
}

- (void)setupShopServiceView
{
    
    UIView * totalView = [[UIView alloc]init];
    totalView.backgroundColor = [UIColor redColor];
    totalView.layer.masksToBounds = YES;
    [totalView.layer setCornerRadius:3];
    [self.contentView addSubview:totalView];
    self.totalView = totalView;
    
    UILabel * nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 17)];
    nameLabel.text = @"店铺服务";
    nameLabel.font = [UIFont systemFontOfSize:14];
    [totalView addSubview:nameLabel];
    
    UIView * lineView =[[UIView alloc]init];
    lineView.backgroundColor = RGBColor(241, 237, 238);
    [totalView addSubview:lineView];
    self.oneLineView = lineView;
    
    UIImageView * timeImageView = [[UIImageView alloc]init];
    timeImageView.image = [UIImage imageNamed:@"store_opendatetime"];
    [totalView addSubview:timeImageView];
    self.timeImageView = timeImageView;
    
    UILabel * timeLabel = [[UILabel alloc]init];
    timeLabel.text = @"周一至周日 08:00-23:00";
    timeLabel.textColor = [UIColor lightGrayColor];
    timeLabel.font = [UIFont systemFontOfSize:13];
    [totalView addSubview:timeLabel];
    self.timeLabel = timeLabel;
    
    UIView * twoLineView =[[UIView alloc]init];
    twoLineView.backgroundColor = RGBColor(241, 237, 238);
    [totalView addSubview:twoLineView];
    self.twoLineView = twoLineView;
    
    
    UIImageView * locationImageView = [[UIImageView alloc]init];
    locationImageView.image = [UIImage imageNamed:@"store_address"];
    [totalView addSubview:locationImageView];
    self.locationImageView = locationImageView;
    
    UILabel * locationLabel = [[UILabel alloc]init];
    locationLabel.text = @"雨花区芙蓉中路与劳动西路东北角";
    locationLabel.textColor = [UIColor lightGrayColor];
    locationLabel.font = [UIFont systemFontOfSize:13];
    [totalView addSubview:locationLabel];
    self.locationLabel = locationLabel;
}

@end
